// 导入express模块
const express = require('express')
// 导入express服务器实例
const app = express()

// 解决跨域问题
const cors = require('cors')
app.use(cors())

const bodyParser = require('body-parser')
const multiparty = require('connect-multiparty')
// 处理 x-www-form-urlencoded 
app.use(bodyParser.urlencoded({ extended: false }))
// 处理 mutipart/form-data
app.use(multiparty())
// 处理 application/json
app.use(bodyParser.json())

const useRouter = require('./router/device')
app.use('/api',useRouter)

const useRouter2 = require('./router/huaweiyun')
app.use('/huawei',useRouter2)
const userRouter = require('./router/user')
app.use('/user',userRouter)
const demoRouter = require('./router/demo')
app.use('/demo',demoRouter)

//一个简单的测试接口
app.get('/test',(req,res)=>{
    res.send('测试用的接口')
})

// 调用app.listen方法，指定端口号并启动服务器
app.listen(3001,function () {
    console.log('server is running at port:3001......');
})